﻿using ImoviesBlazor.Server.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace ImoviesBlazor.Server.Data
{
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser, IdentityRole<Guid>, Guid>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

        // 实体表
        public DbSet<Shared.Entities.Teleplay> Teleplays { get; set; }
        public DbSet<Shared.Entities.Movie> Movies { get; set; }
        public DbSet<Shared.Entities.Animation> Animations { get; set; }
        public DbSet<Shared.Entities.TeleplayVlink> TeleplayVlinks { get; set; }
        public DbSet<Shared.Entities.MovieVlink> MovieVlinks { get; set; }
        public DbSet<Shared.Entities.AnimationVlink> AnimationVlinks { get; set; }
        public DbSet<Shared.Entities.AnnualReview> AnnualReviews { get; set; }



        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<Shared.Entities.Teleplay>(x =>
            {
                x.HasIndex(p => p.Name);
                x.HasIndex(p => p.Year);
            });

            builder.Entity<Shared.Entities.Movie>(x =>
            {
                x.HasIndex(p => p.Name);
                x.HasIndex(p => p.Year);
            });

            builder.Entity<Shared.Entities.Animation>(x =>
            {
                x.HasIndex(p => p.Name);
                x.HasIndex(p => p.Year);
            });

            builder.Entity<Shared.Entities.TeleplayVlink>(x =>
            {
                x.HasIndex(p => p.TeleplayId);
            });

            builder.Entity<Shared.Entities.MovieVlink>(x =>
            {
                x.HasIndex(p => p.MovieId);
            });

            builder.Entity<Shared.Entities.AnimationVlink>(x =>
            {
                x.HasIndex(p => p.AnimationId);
            });


            builder.Entity<Shared.Entities.AnnualReview>(x =>
            {
                x.HasIndex(p => p.VideoCate);
            });
        }

    }
}
